package chapter4;
import java.util.Random;

public class ConstructorTest {
    public static void main(String[] args) {
        Employee_1[] staff = new Employee_1[3];
        staff[0] = new Employee_1("Harry",40000);
        staff[1] = new Employee_1(60000);
        staff[2] = new Employee_1();

        for (Employee_1 e:staff){
            System.out.println("name="+e.getName()+",id="+e.getId()+",salary="+e.getSalary());
        }

    }
}
class Employee_1{
    private static int nextId;
    private int id;
    private String name = "";
    private double salary;

    //静态字段初始化
    static{
        Random generator = new Random();
        nextId = generator.nextInt(10000);
    }
    //对象初始化
    {
        id = nextId;
        nextId++;
    }
    //重载构造器
    public Employee_1(String n,double s){
        name = n;
        salary = s;
    }
    public Employee_1(double s){
        this("Employee #"+ nextId,s);
    }
    public Employee_1(){}

    public String getName(){
        return name;
    }
    public double getSalary(){
        return salary;
    }
    public int getId(){
        return  id;
    }

}
